-- background: 2660 from stack: in -- bmap block id: 4192 -- flags: 4000 -- background id: 0 -- name: Function Plotter ----- HyperTalk script ----- on domainExp global dExpL, dExpR if the hilight of bkgnd button "Limit Domain" is true then if the hilight of bkgnd button domainLLT is true then put "x >" && field domainLL into dExpL else put "x ≥" && field domainLL into dExpL end if if the hilight of bkgnd button domainULT is true then put "x <" && field domainUL into dExpR else put "x ≤" && field domainUL into dExpR end if else put empty into dExpL put empty into dExpR end if end domainExp function leftOfDomain x global dExpL if dExpL is empty then return false else return not the value of dExpL end if end leftOfDomain function inDomain x global dExpL, dExpR if dExpL is empty then return true else return the value of dExpL and the value of dExpR end if end inDomain function rightOfDomain x global dExpR if dExpR is empty then return false else return not the value of dExpR end if end rightOfDomain on stdScale global xCorner, yCorner put -10 into xCorner put -10 into yCorner put 1 into field xUnit put 1 into field yUnit end stdScale on shiftGraph dir global gHSize, gVSize, xCorner, yCorner if dir is "Left" then subtract gHSize * field xUnit from xCorner else if dir is "Right" then add gHSize * field xUnit to xCorner else if dir is "Up" then add gVSize * field yUnit to yCorner else if dir is "Down" then subtract gVSize * field yUnit from yCorner else if dir is "Origin" then put - gHSize * field xUnit into xCorner put - gVSize * field yUnit into yCorner end if end if end if end if end if end shiftGraph on zoomOut mag global gHSize, gVSize, xCorner, yCorner add ( 1 - mag ) * gHSize * field xUnit to xCorner multiply field xUnit by mag add ( 1 - mag ) * gVSize * field yUnit to yCorner multiply field yUnit by mag end zoomOut on zoomIn mag global gLeft, gTop, gRight, gBottom, gHSize, gVSize global xCorner, yCorner put "Click on the center of the new graph." into message put false into ok repeat until ok wait until the mouseClick is true get the mouseLoc put item 1 of it into x0 put item 2 of it into y0 if x0 < gLeft or x0 > gRight or y0 < gTop or y0 > gBottom then answer "You must click inside the graph box." else put true into ok end if end repeat put empty into message hide message put field xUnit * round( xPtoC( x0 ) / field xUnit ) into xCenter put field yUnit * round( yPtoC( y0 ) / field yUnit ) into yCenter divide field xUnit by mag divide field yUnit by mag put xCenter - gHSize * field xUnit into xCorner put yCenter - gVSize * field yUnit into yCorner end zoomIn function xPtoC p global gLeft, gUnit, xCorner return xCorner + ( p - gLeft ) / gUnit * field xUnit end xPtoC function yPtoC p global gBottom, gUnit, yCorner return yCorner - ( p - gBottom ) / gUnit * field yUnit end yPtoC function xCtoP c global gLeft, gRight, gUnit, xCorner return gLeft + round(( c - xCorner ) / field xUnit * gUnit ) end xCtoP function yCtoP c global gTop, gBottom, gUnit, yCorner return gBottom - round(( c - yCorner ) / field yUnit * gUnit ) end yCtoP function xCtoPClip c global gLeft, gRight, gUnit, xCorner get gLeft + round(( c - xCorner ) / field xUnit * gUnit ) if it < gLeft then return gLeft else if it > gRight then return gRight else return it end if end if end xCtoPClip function yCtoPClip c global gTop, gBottom, gUnit, yCorner get gBottom - round(( c - yCorner ) / field yUnit * gUnit ) if it < gTop then return gTop else if it > gBottom then return gBottom else return it end if end if end yCtoPClip function mConstrain hMouse global mLeftBound, mRightBound if hMouse < mLeftBound then return mLeftBound else if hMouse > mRightBound then return mRightBound else return hMouse end if end if end mConstrain on drawGraphBox global gLeft, gTop, gUnit, gHSize, gVSize global gHMid, gVMid, gRight, gBottom choose rectangle tool set lineSize to 1 drag from gLeft, gTop to gRight, gBottom choose line tool put gHSize - 1 into nTicks put gLeft into x repeat while x <= gRight if nTicks = gHSize - 1 then put 4 into tickLen put 0 into nTicks else put 2 into tickLen add 1 to nTicks end if drag from x, gTop to x, gTop - tickLen drag from x, gBottom to x, gBottom + tickLen add gUnit to x end repeat put gVSize - 1 into nTicks put gTop into y repeat while y <= gBottom if nTicks = gVSize - 1 then put 4 into tickLen put 0 into nTicks else put 2 into tickLen add 1 to nTicks end if drag from gLeft, y to gLeft - tickLen, y drag from gRight, y to gRight + tickLen, y add gUnit to y end repeat choose browse tool set the rect of field yTop to gLeft - 54, gTop - 6, gLeft - 4, gTop + 6 set the rect of field yUnitLabel to gLeft - 54, gVMid - 11, gLeft - 4, gVMid + 1 set the rect of field yUnit to gLeft - 54, gVMid, gLeft - 4, gVMid + 12 set the rect of field yBottom to gLeft - 54, gBottom - 6, gLeft - 4, gBottom + 6 set the rect of field xLeft to gLeft - 25, gBottom + 7, gLeft + 25, gBottom + 19 set the rect of field xUnitLabel to gHMid - 49, gBottom + 7, gHMid + 1, gBottom + 19 set the rect of field xUnit to gHMid, gBottom + 7, gHMid + 50, gBottom + 19 set the rect of field xRight to gRight - 25, gBottom + 7, gRight + 25, gBottom + 19 end drawGraphBox on eraseGraph global gLeft, gTop, gRight, gBottom choose select tool drag from gLeft + 1, gTop + 1 to gRight - 1, gBottom - 1 doMenu "Clear Picture" end eraseGraph on eraseFgnd global gLeft, gTop, gRight, gBottom choose select tool drag from gLeft - 4, gTop - 4 to gRight + 4, gBottom + 4 doMenu "Clear Picture" end eraseFgnd on drawAxes global gLeft, gTop, gRight, gBottom, gUnit, xCorner, yCorner global gYofXAxis, gXofYAxis put xCorner into field xLeft put xPtoC( gRight ) into field xRight put yCorner into field yBottom put yPtoC( gTop ) into field yTop put yCtoP( 0 ) into gYofXAxis put xCtoP( 0 ) into gXofYAxis choose line tool set lineSize to 1 set pattern to 22 if gYofXAxis > gTop and gYofXAxis < gBottom then drag from gLeft, gYofXAxis to gRight, gYofXAxis with optionKey end if if gXofYAxis > gLeft and gXofYAxis < gRight then drag from gXofYAxis, gTop to gXofYAxis, gBottom with optionKey end if end drawAxes function yCalc x global fxCmd, gTop, gBottom do fxCmd return y end yCalc on plotFunction global gLeft, gRight, fxCmd, xPLim, yPLim, xNLim, yNLim global mkrSet, mLeftBound, mRightBound if line 1 of field fx is empty then answer "Specify f(x) first." else if rightOfDomain( field xLeft ) or leftOfDomain( field xRight ) then answer "The domain of f(x) is outside this view." else put "put" && line 1 of field fx && "into y" into fxCmd put "Now plotting f(x) =" && line 1 of field fx into message set the editBkgnd to true choose line tool set lineSize to 1 put gLeft into mLeftBound repeat while leftOfdomain( xPtoC( mLeftBound )) add 1 to mLeftBound end repeat put mLeftBound into mRightBound put mLeftBound into xScreen0 put xScreen0 into xPLim put xScreen0 into xNLim put yCalc( xPtoC( xScreen0 )) into y0 put yCtoPClip( y0 ) into yScreen0 put y0 into yPLim put y0 into yNLim repeat with xScreen = mLeftBound + 1 to gRight get xPtoC( xScreen ) if rightOfDomain( it ) then exit repeat put xScreen into mRightBound get yCalc( it ) put yCtoPClip( it ) into yScreen drag from xScreen0, yScreen0 to xScreen, yScreen if it < yNLim then put xScreen into xNLim put it into yNLim else if it > yPLim then put xScreen into xPLim put it into yPLim end if end if put xScreen into xScreen0 put yScreen into yScreen0 end repeat put xPtoC( xPLim ) into xPLim put xPtoC( xNLim ) into xNLim put empty into message hide message choose browse tool if mLeftBound = mRightBound then answer "The domain of f(x) is too small for this view." end if if mkrSet is true then send showMarkers to this card end if end if end plotFunction -- part 3 (field) -- low flags: 01 -- high flags: 0001 -- rect: left=324 top=328 right=340 bottom=374 -- title width / last selected line: 0 -- icon id / first selected line: 0 / 0 -- text alignment: 0 -- font id: 2 -- text size: 9 -- style flags: 0 -- line height: 12 -- part name: xUnit ----- HyperTalk script ----- on closeField if field xUnit <= 0 then answer "x unit must be positive." put 1 into field xUnit end if end closeField -- part 1 (field) -- low flags: 00 -- high flags: 0002 -- rect: left=156 top=30 right=45 bottom=505 -- title width / last selected line: 0 -- icon id / first selected line: 0 / 0 -- text alignment: 0 -- font id: 2 -- text size: 10 -- style flags: 0 -- line height: 13 -- part name: fx ----- HyperTalk script ----- on closeField eraseMarkers end closeField -- part 4 (field) -- low flags: 01 -- high flags: 0001 -- rect: left=150 top=201 right=213 bottom=200 -- title width / last selected line: 0 -- icon id / first selected line: 0 / 0 -- text alignment: 1 -- font id: 2 -- text size: 9 -- style flags: 0 -- line height: 12 -- part name: yUnit ----- HyperTalk script ----- on closeField if field yUnit <= 0 then answer "y unit must be positive." put 1 into field yUnit end if end closeField -- part 10 (field) -- low flags: 01 -- high flags: 0001 -- rect: left=419 top=328 right=340 bottom=469 -- title width / last selected line: 0 -- icon id / first selected line: 0 / 0 -- text alignment: 1 -- font id: 2 -- text size: 9 -- style flags: 0 -- line height: 12 -- part name: xRight -- part 11 (field) -- low flags: 01 -- high flags: 0001 -- rect: left=179 top=328 right=340 bottom=229 -- title width / last selected line: 0 -- icon id / first selected line: 0 / 0 -- text alignment: 1 -- font id: 2 -- text size: 9 -- style flags: 0 -- line height: 12 -- part name: xLeft -- part 12 (field) -- low flags: 01 -- high flags: 0001 -- rect: left=150 top=315 right=327 bottom=200 -- title width / last selected line: 0 -- icon id / first selected line: 0 / 0 -- text alignment: 65535 -- font id: 2 -- text size: 9 -- style flags: 0 -- line height: 12 -- part name: yBottom -- part 13 (field) -- low flags: 01 -- high flags: 0001 -- rect: left=150 top=75 right=87 bottom=200 -- title width / last selected line: 0 -- icon id / first selected line: 0 / 0 -- text alignment: 65535 -- font id: 2 -- text size: 9 -- style flags: 0 -- line height: 12 -- part name: yTop -- part 16 (button) -- low flags: 00 -- high flags: A004 -- rect: left=456 top=228 right=244 bottom=506 -- title width / last selected line: 0 -- icon id / first selected line: 0 / 0 -- text alignment: 1 -- font id: 0 -- text size: 12 -- style flags: 0 -- line height: 16 -- part name: 2x ----- HyperTalk script ----- on mouseUp zoomIn 2 updateGraph end mouseUp -- part 17 (button) -- low flags: 00 -- high flags: A004 -- rect: left=456 top=246 right=262 bottom=506 -- title width / last selected line: 0 -- icon id / first selected line: 0 / 0 -- text alignment: 1 -- font id: 0 -- text size: 12 -- style flags: 0 -- line height: 16 -- part name: 10x ----- HyperTalk script ----- on mouseUp zoomIn 10 updateGraph end mouseUp -- part 18 (button) -- low flags: 00 -- high flags: A004 -- rect: left=456 top=264 right=280 bottom=506 -- title width / last selected line: 0 -- icon id / first selected line: 0 / 0 -- text alignment: 1 -- font id: 0 -- text size: 12 -- style flags: 0 -- line height: 16 -- part name: Std. ----- HyperTalk script ----- on mouseUp stdScale updateGraph end mouseUp -- part 19 (button) -- low flags: 00 -- high flags: A004 -- rect: left=456 top=282 right=298 bottom=506 -- title width / last selected line: 0 -- icon id / first selected line: 0 / 0 -- text alignment: 1 -- font id: 0 -- text size: 12 -- style flags: 0 -- line height: 16 -- part name: 1/2x ----- HyperTalk script ----- on mouseUp zoomOut 2 updateGraph end mouseUp -- part 20 (button) -- low flags: 00 -- high flags: A004 -- rect: left=456 top=300 right=316 bottom=506 -- title width / last selected line: 0 -- icon id / first selected line: 0 / 0 -- text alignment: 1 -- font id: 0 -- text size: 12 -- style flags: 0 -- line height: 16 -- part name: 1/10x ----- HyperTalk script ----- on mouseUp zoomOut 10 updateGraph end mouseUp -- part 31 (button) -- low flags: 00 -- high flags: A004 -- rect: left=456 top=108 right=124 bottom=506 -- title width / last selected line: 0 -- icon id / first selected line: 0 / 0 -- text alignment: 1 -- font id: 0 -- text size: 12 -- style flags: 0 -- line height: 16 -- part name: Left ----- HyperTalk script ----- on mouseUp shiftGraph "Left" updateGraph end mouseUp -- part 32 (button) -- low flags: 00 -- high flags: A004 -- rect: left=456 top=162 right=178 bottom=506 -- title width / last selected line: 0 -- icon id / first selected line: 0 / 0 -- text alignment: 1 -- font id: 0 -- text size: 12 -- style flags: 0 -- line height: 16 -- part name: Up ----- HyperTalk script ----- on mouseUp shiftGraph "Up" updateGraph end mouseUp -- part 33 (button) -- low flags: 00 -- high flags: A004 -- rect: left=456 top=144 right=160 bottom=506 -- title width / last selected line: 0 -- icon id / first selected line: 0 / 0 -- text alignment: 1 -- font id: 0 -- text size: 12 -- style flags: 0 -- line height: 16 -- part name: Origin ----- HyperTalk script ----- on mouseUp shiftGraph "Origin" updateGraph end mouseUp -- part 34 (button) -- low flags: 00 -- high flags: A004 -- rect: left=456 top=180 right=196 bottom=506 -- title width / last selected line: 0 -- icon id / first selected line: 0 / 0 -- text alignment: 1 -- font id: 0 -- text size: 12 -- style flags: 0 -- line height: 16 -- part name: Down ----- HyperTalk script ----- on mouseUp shiftGraph "Down" updateGraph end mouseUp -- part 35 (button) -- low flags: 00 -- high flags: A004 -- rect: left=456 top=126 right=142 bottom=506 -- title width / last selected line: 0 -- icon id / first selected line: 0 / 0 -- text alignment: 1 -- font id: 0 -- text size: 12 -- style flags: 0 -- line height: 16 -- part name: Right ----- HyperTalk script ----- on mouseUp shiftGraph "Right" updateGraph end mouseUp -- part 36 (button) -- low flags: 00 -- high flags: A005 -- rect: left=121 top=52 right=70 bottom=229 -- title width / last selected line: 0 -- icon id / first selected line: 0 / 0 -- text alignment: 1 -- font id: 0 -- text size: 12 -- style flags: 0 -- line height: 16 -- part name: Limit Domain ----- HyperTalk script ----- on mouseUp if the highlight of bkgnd button "Limit Domain" is true then put field xLeft into field domainLL put field xRight into field domainUL send mouseUp to bkgnd button domainLLE send mouseUp to bkgnd button domainULE set the lockText of field domainLL to false set the lockText of field domainUL to false set the rect of bkgnd button dLimitMask to 230,45,451,46 else set the rect of bkgnd button dLimitMask to 230,45,451,76 set the lockText of field domainLL to true set the lockText of field domainUL to true end if domainExp end mouseUp -- part 37 (field) -- low flags: 01 -- high flags: 0002 -- rect: left=232 top=53 right=68 bottom=314 -- title width / last selected line: 0 -- icon id / first selected line: 0 / 0 -- text alignment: 65535 -- font id: 2 -- text size: 10 -- style flags: 0 -- line height: 13 -- part name: domainLL ----- HyperTalk script ----- on openField global oldVal put field domainLL into oldVal end openField on closeField global oldVal domainExp if field domainUL < field domainLL or ( field domainUL = field domainLL and not inDomain( field domainUL )) then answer "Not a valid domain." put oldVal into field domainLL domainExp end if end closeField -- part 39 (button) -- low flags: 00 -- high flags: 0006 -- rect: left=313 top=47 right=61 bottom=331 -- title width / last selected line: 0 -- icon id / first selected line: 0 / 0 -- text alignment: 1 -- font id: 0 -- text size: 12 -- style flags: 0 -- line height: 16 -- part name: domainLLT ----- HyperTalk script ----- on mouseUp if field domainLL = field domainUL then answer "Not a valid domain." else set the hilight of bkgnd button domainLLE to false set the hilight of bkgnd button domainLLT to true domainExp end if end mouseUp -- part 40 (button) -- low flags: 00 -- high flags: 4006 -- rect: left=313 top=60 right=74 bottom=331 -- title width / last selected line: 0 -- icon id / first selected line: 0 / 0 -- text alignment: 1 -- font id: 0 -- text size: 12 -- style flags: 0 -- line height: 16 -- part name: domainLLE ----- HyperTalk script ----- on mouseUp set the hilight of bkgnd button domainLLT to false set the hilight of bkgnd button domainLLE to true domainExp end mouseUp -- part 41 (button) -- low flags: 00 -- high flags: 0006 -- rect: left=350 top=47 right=61 bottom=368 -- title width / last selected line: 0 -- icon id / first selected line: 0 / 0 -- text alignment: 1 -- font id: 0 -- text size: 12 -- style flags: 0 -- line height: 16 -- part name: domainULT ----- HyperTalk script ----- on mouseUp if field domainLL = field domainUL then answer "Not a valid domain." else set the hilight of bkgnd button domainULE to false set the hilight of bkgnd button domainULT to true domainExp end if end mouseUp -- part 42 (button) -- low flags: 00 -- high flags: 4006 -- rect: left=350 top=60 right=74 bottom=368 -- title width / last selected line: 0 -- icon id / first selected line: 0 / 0 -- text alignment: 1 -- font id: 0 -- text size: 12 -- style flags: 0 -- line height: 16 -- part name: domainULE ----- HyperTalk script ----- on mouseUp set the hilight of bkgnd button domainULT to false set the hilight of bkgnd button domainULE to true domainExp end mouseUp -- part 44 (field) -- low flags: 01 -- high flags: 0002 -- rect: left=367 top=53 right=68 bottom=449 -- title width / last selected line: 0 -- icon id / first selected line: 0 / 0 -- text alignment: 0 -- font id: 2 -- text size: 10 -- style flags: 0 -- line height: 13 -- part name: domainUL ----- HyperTalk script ----- on openField global oldVal put field domainUL into oldVal end openField on closeField global oldVal domainExp if field domainUL < field domainLL or ( field domainUL = field domainLL and not inDomain( field domainUL )) then answer "Not a valid domain." put oldVal into field domainUL domainExp end if end closeField -- part 45 (button) -- low flags: 00 -- high flags: 0001 -- rect: left=230 top=45 right=76 bottom=451 -- title width / last selected line: 0 -- icon id / first selected line: 0 / 0 -- text alignment: 1 -- font id: 0 -- text size: 12 -- style flags: 0 -- line height: 16 -- part name: dLimitMask -- part 46 (button) -- low flags: 00 -- high flags: 8004 -- rect: left=456 top=52 right=70 bottom=506 -- title width / last selected line: 0 -- icon id / first selected line: 0 / 0 -- text alignment: 1 -- font id: 0 -- text size: 12 -- style flags: 0 -- line height: 16 -- part name: Plot ----- HyperTalk script ----- on mouseUp if field fx is empty then answer "Specify f(x) first." else updateGraph plotFunction end if end mouseUp -- part 48 (field) -- low flags: 01 -- high flags: 0001 -- rect: left=150 top=190 right=202 bottom=200 -- title width / last selected line: 0 -- icon id / first selected line: 0 / 0 -- text alignment: 1 -- font id: 2 -- text size: 9 -- style flags: 0 -- line height: 12 -- part name: yUnitLabel ----- HyperTalk script ----- on closeField if field yUnit <= 0 then answer "y unit must be positive." put 1 into field yUnit end if end closeField -- part 49 (field) -- low flags: 01 -- high flags: 0001 -- rect: left=275 top=328 right=340 bottom=325 -- title width / last selected line: 0 -- icon id / first selected line: 0 / 0 -- text alignment: 65535 -- font id: 2 -- text size: 9 -- style flags: 0 -- line height: 12 -- part name: xUnitLabel ----- HyperTalk script ----- on closeField if field xUnit <= 0 then answer "x unit must be positive." put 1 into field xUnit end if end closeField -- part 51 (field) -- low flags: 01 -- high flags: 0001 -- rect: left=120 top=30 right=45 bottom=156 -- title width / last selected line: 0 -- icon id / first selected line: 0 / 0 -- text alignment: 65535 -- font id: 2 -- text size: 10 -- style flags: 0 -- line height: 13 -- part name: fxLabel ----- HyperTalk script ----- on closeField if field yUnit <= 0 then answer "y unit must be positive." put 1 into field yUnit end if end closeField -- part 52 (field) -- low flags: 01 -- high flags: 0001 -- rect: left=456 top=85 right=108 bottom=506 -- title width / last selected line: 0 -- icon id / first selected line: 0 / 0 -- text alignment: 1 -- font id: 2 -- text size: 10 -- style flags: 0 -- line height: 11 -- part name: shiftLabel ----- HyperTalk script ----- on closeField if field yUnit <= 0 then answer "y unit must be positive." put 1 into field yUnit end if end closeField -- part 53 (field) -- low flags: 01 -- high flags: 0001 -- rect: left=456 top=205 right=228 bottom=506 -- title width / last selected line: 0 -- icon id / first selected line: 0 / 0 -- text alignment: 1 -- font id: 2 -- text size: 10 -- style flags: 0 -- line height: 11 -- part name: changeLabel ----- HyperTalk script ----- on closeField if field yUnit <= 0 then answer "y unit must be positive." put 1 into field yUnit end if end closeField -- part 55 (button) -- low flags: 00 -- high flags: 0001 -- rect: left=126 top=317 right=339 bottom=161 -- title width / last selected line: 0 -- icon id / first selected line: 2162 / 2162 -- text alignment: 1 -- font id: 0 -- text size: 12 -- style flags: 0 -- line height: 16 -- part name: Return ----- HyperTalk script ----- on mouseUp visual effect iris close go to card Title end mouseUp